package com.wn.service.assistant

import android.content.Context
import androidx.appcompat.app.AlertDialog
import com.blankj.utilcode.util.ToastUtils
import com.didichuxing.doraemonkit.kit.AbstractKit
import com.wn.common.utils.*
import com.wn.service.R

/**
 * @Author: wn
 * @Date: 2023/2/21 16:47
 * @Description: 自定义的调试工具类，用于 添加 到 doKit 里切换 host
 */
class ServiceHostKit : AbstractKit() {

  private val hostMap = mapOf(
    "开发环境Host" to HOST_DEV,
    "测试环境Host(无)" to HOST_QA,
    "线上正式Host(无)" to HOST_PRODUCT
  )

  private val names = hostMap.keys.toTypedArray()
  private val hosts = hostMap.values.toTypedArray()

  override val icon = R.drawable.icon_server_host

  override val name = R.string.change_server_host_dokit

  override fun onAppInit(context: Context?) {
    //
  }

  override fun onClick(context: Context?) {
    // BaseHost 开发或者生产 在 map 中位置 取余 map的个数 余 0 1 2
    val pos = hostMap.values.indexOf(getBaseHost()) % hosts.size
    // 弹窗，用于显示跟选择不同的host配置
    context ?: return ToastUtils.showShort("context is null")
    AlertDialog.Builder(context)
      .setTitle(context.getString(R.string.change_server_host_dokit))
      .setSingleChoiceItems(names, pos) { dialog, which ->
        setBaseHost(hosts[which])
        dialog.dismiss()
      }
      .show()
  }


}